package com.wk.code.wkserver.controller.admin;


import com.wk.code.wkserver.controller.common.BaseController;
import com.wk.code.wkserver.entity.User;
import com.wk.code.wkserver.request.admin.TechUserVerifyRequest;
import com.wk.code.wkserver.request.app.SetCustomerRequest;
import com.wk.code.wkserver.request.app.UserRequest;
import com.wk.code.wkserver.response.admin.UserInfoDetailResponse;
import com.wk.code.wkserver.response.base.PageInfo;
import com.wk.code.wkserver.response.result.R;
import com.wk.code.wkserver.service.IUserInfoService;
import com.wk.code.wkserver.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 控制层
 *
 * @Author wq
 * @Date 2021-03-16
 **/
@RestController
@RequestMapping("admin/user")
@AllArgsConstructor
@Api(tags = "admin-后台用户管理")
public class AdminUserController extends BaseController {

    private final IUserService userService;

    private final IUserInfoService userInfoService;


    /**
     * 需求用户列表
     *
     * @param userRequest userRequest
     * @return R
     */
    @ApiOperation(value = "需求用户列表")
    @PostMapping("/demandUserPage")
    public R<PageInfo<User>> demandUserPage(@RequestBody UserRequest userRequest) {
        return R.success(userService.page(userRequest));
    }


    /**
     * 技术用户列表
     *
     * @param userRequest userRequest
     * @return R
     */
    @ApiOperation(value = "技术用户列表")
    @PostMapping("/techUserPage")
    public R<PageInfo<User>> techUserPage(@RequestBody UserRequest userRequest) {
        return R.success(userService.page(userRequest));
    }

    /**
     * 用户详情
     *
     * @param userId 用户ID
     * @return R
     */
    @ApiOperation(value = "用户详情")
    @GetMapping("/detail")
    public R<UserInfoDetailResponse> detail(Integer userId) {
        return R.success(userService.detail(userId));
    }

    /**
     * 审核技术申请
     *
     * @param userRequest userRequest
     * @return R
     */
    @ApiOperation(value = "审核技术申请")
    @PostMapping("/verifyTechUser")
    public R<Void> verifyTechUser(@RequestBody TechUserVerifyRequest userRequest) {
        userService.applyVerifyTech(getSysUserId(), userRequest);
        return R.success();
    }


    /**
     * 封禁用户
     *
     * @param userId userId
     * @return R
     */
    @ApiOperation(value = "封禁用户")
    @GetMapping("/prohibitUser")
    public R<Void> prohibitUser(Integer userId) {
        userInfoService.prohibitUser(userId);
        return R.success();
    }

    /**
     * 设置成为客服
     *
     * @param userRequest userRequest
     * @return R
     */
    @ApiOperation(value = "设置成为客服")
    @PostMapping("/setCustomer")
    public R<Void> setCustomer(@RequestBody SetCustomerRequest userRequest) {
        userInfoService.setCustomer(userRequest);
        return R.success();
    }

}